#include <iostream>
#include <algorithm>
#define MAXN 40005
#define INF 1 << 30
using namespace std;
int map[MAXN], dp[MAXN];
int N, P;
void solve();

int main() {
    ios::sync_with_stdio(false);
    cin >> N;
    while (N--) {
        cin >> P;
        int t;
        for (int i = 0; i < P; i++) {
            cin >> t;
            map[i] = t;
        } 
        solve();
    }
}


void solve() {
    fill(dp, dp + P, INF);
    for (int i = 0; i < P; i++) {
        *lower_bound(dp, dp + P, map[i]) = map[i];
    }

    cout << (lower_bound(dp, dp + P, INF) - dp) << endl;
}
